package com.example.demo.thread.future;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author luowj12
 * @since 2021/5/31 15:46
 */
public class TableTest {

    public static void main(String[] args) {
        List<Callable<List>> taskList = new ArrayList();
        for (int shardingIndex = 0; shardingIndex < 1024; shardingIndex++) {
            int i = shardingIndex;
            taskList.add(() -> (getProcessingAccountList(i)));
            /*taskList.add(new Callable() {
                @Override
                public Integer call() throws Exception {
                    int sum = 0;
                    for (int i = 0; i < 100; i++) {

                        sum += i;
                    }
                    return sum;
                }
            });*/
        }
        List list = null;
        try {
            list = executeTask(taskList);
        } catch (Exception e) {

        }
}

    private static ExecutorService executorService = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS,
            new ArrayBlockingQueue(100));

    public static <T> List<T> executeTask(Collection<? extends Callable<T>> tasks) throws Exception {
        List<T> result = new ArrayList();
        List<Future<T>> futures = executorService.invokeAll(tasks);
        for (Future<T> future : futures) {
            result.add(future.get());
        }
        return result;
    }

    public static  List getProcessingAccountList(int shardingIndex){
        return new ArrayList();
    }
}
